﻿namespace MEF_Test.Bricks
{
    using System;
    using System.Configuration;

    public class MappingConfigElement : ConfigurationElement
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MappingConfigElement"/> class.
        /// </summary>
        public MappingConfigElement()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MappingConfigElement"/> class.
        /// </summary>
        /// <param name="contract">The contract.</param>
        /// <param name="type">The type to map the specified <see cref="Contract"/> to.</param>
        public MappingConfigElement(string contract, string type)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            Contract = contract;
            Type = type;
        }

        #endregion

        #region Properties        

        /// <summary>
        /// Gets or sets the contract.
        /// </summary>
        /// <value>The contract.</value>
        [ConfigurationProperty("contract", DefaultValue = null, IsRequired = true, IsKey = true)]
        public string Contract
        {
            get
            {
                return (string)this["contract"];
            }

            set
            {
                this["contract"] = value;
            }
        }


        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type to map the contract to.</value>
        [ConfigurationProperty("type", DefaultValue = null, IsRequired = true, IsKey = false)]
        public string Type
        {
            get
            {
                return (string)this["type"];
            }

            set
            {
                this["type"] = value;
            }
        }

        #endregion
    }
}